// 自定义dialog
import 'package:flutter/material.dart';

class ScrcpyConnectDialog extends Dialog {
  String title;
  String content;
  final TextEditingController _controllerMaLv = TextEditingController();
  final TextEditingController _controllerSize = TextEditingController();
  final TextEditingController _controllerZhenLv = TextEditingController();
  Function()? onClosed;
  Function(int malv,int size,int fps)? onConfirm;

  ScrcpyConnectDialog(
      {Key? key,
      required this.title,
      required this.onClosed,
      required this.onConfirm,
      this.content = ""})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    _controllerMaLv.value = const TextEditingValue(text: "2");
    _controllerSize.value = const TextEditingValue(text: "800");
    _controllerZhenLv.value = const TextEditingValue(text: "15");
    return Material(
      type: MaterialType.transparency,
      child: Center(
          child: ClipRRect(
        borderRadius: BorderRadius.circular(10),
        child: Container(
          height: 300,
          width: 300,
          padding: const EdgeInsets.all(10),
          color: Colors.white,
          child: Column(
            children: <Widget>[
              Container(
                height: 245,
                padding: const EdgeInsets.all(10),
                width: MediaQuery.of(context).size.width,
                child: Column(
                  children: [
                    Container(margin: const EdgeInsets.fromLTRB(0, 0, 0, 0),child: TextField(
                        keyboardType: TextInputType.number,
                        controller: _controllerMaLv,
                        decoration: const InputDecoration(
                          labelText: '码率',
                          border: OutlineInputBorder(),
                        )),),
                    Container(margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),child: TextField(
                        keyboardType: TextInputType.number,
                        controller: _controllerSize,
                        decoration: const InputDecoration(
                          labelText: '最大尺寸',
                          border: OutlineInputBorder(),
                        )),),
                    Container(margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),child: TextField(
                        keyboardType: TextInputType.number,
                        controller: _controllerZhenLv,
                        decoration: const InputDecoration(
                          labelText: '帧率',
                          border: OutlineInputBorder(),
                        )),)
                  ],
                ),
              ),
              Row(
                children: [
                  Expanded(
                      flex: 1,
                      child: TextButton(
                        onPressed: () => {onClosed?.call()},
                        child: Text("取消"),
                      )),
                  Expanded(
                      flex: 1,
                      child: TextButton(
                        onPressed: () => {
                          onConfirm?.call(int.parse(_controllerMaLv.value.text),int.parse(_controllerSize.value.text),int.parse(_controllerZhenLv.value.text))
                        },
                        child: Text("确认"),
                      ))
                ],
              )
            ],
          ),
        ),
      )),
    );
  }
}
